home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir43
/
med300.zip
/
MEEDIT.CLA
< prev
next >
Wrap
Text File
|
1994-02-22
|
28KB
|
497 lines
!▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
!█ █
!█ MEEDIT.CLA █
!█ Main edit procedure for MemoEdit █
!█ █
!█ Revision Number: 1 █
!█ Revision Date : 22-Feb-94 █
!█ █
!█ Revision History █
!█ 1 Created █
!█ █
!▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
MEMBER('MEMOEDIT')
!═════════════════════════════════════════════════════════════════════════
! Main edit procedure for MemoEdit
!═════════════════════════════════════════════════════════════════════════
ME_Edit PROCEDURE
! Equates:
eFileMsg EQUATE('Mark block to PUT, then press ENTER')
eDeleteMsg EQUATE('Mark block to DELETE, then press ENTER')
eCopy1Msg EQUATE('Mark block to COPY, then press ENTER')
eCopy2Msg EQUATE('Point to destination, then press ENTER to COPY')
eMove1Msg EQUATE('Mark block to MOVE, then press ENTER')
eMove2Msg EQUATE('Point to destination, then press ENTER to MOVE')
! Locals:
isKeystroke SHORT ! Last keystroke
bbAlerted BYTE ! ALERTed key pressed
bbCommand BYTE ! Command sequence pressed
bbExit BYTE ! Exit flag
bbNewCol BYTE ! Column change flag
isSavCol SHORT ! Saved column position
sText STRING(80) ! Text string
isTextLen SHORT ! Length of text string
sStatus STRING(76) ! Status line string
rHorizRuler REAL ! Horizontal ruler
ubCodeNdx BYTE ! Code array index
ilStyle LONG ! Line style flags
ubChar BYTE ! Character under cursor
CODE
IF NOT MEU:sHelpID THEN MEU:sHelpID = eHelpID. ! Set default Help ID
IF MEU:bbShowStatus THEN OPEN(wStatus). ! Open status line
isSavCol = 0 ! Reset column
bbNewCol = 0 !
DO EditLoop ! Edit the memo
IF MEU:bbShowStatus THEN CLOSE(wStatus). ! Close status line
SETCURSOR ! Turn off cursor
RETURN !
!──────────────────────────────────────────────────────────────────────────
EditLoop ROUTINE ! Main edit loop
!──────────────────────────────────────────────────────────────────────────
bbExit = 0 ! Clear exit flag
DO UpdatePos ! Update position variables
DO StatusLine ! Display status line
MEU:bbShowStatus = 1 ! Set status line flag
LOOP UNTIL bbExit ! Loop
ME_CurPos() ! Display cursor
ASK ! Get keystroke
isKeystroke = KEYCODE() ! Get keystroke
DO SaveCol ! Save current column
IF INRANGE(isKeystroke, 32, 254) ! If printable char
DO InsChar ! Insert into buffer
ELSE ! Else
bbAlerted = IsAlerted(isKeystroke) ! Save ALERTed status
DO CheckAlerts ! Check for ALERTed keys
IF NOT bbExit ! If exit flag not set
DO EditAction ! Perform edit action
IF NOT bbCommand THEN DO OtherKeys. ! Handle any other keys
. . ! Endif
DO UpdatePos ! Update position variables
IF KEYBOARD() THEN CYCLE. ! Cycle if a key is pending
IF MED:bbBlockMark ! If marking a block
MED:isBlockEnd = MED:usPosition ! Update block end
ME_SetPage() ! Invalidate page
. ! Endif
ME_ShowPage() ! Display page
IF MEU:bbShowStatus THEN DO StatusLine. ! Display status line
MEU:bbShowStatus = 1 ! Set status flag
. ! End loop
!──────────────────────────────────────────────────────────────────────────
CheckAlerts ROUTINE ! Check for ALERTed key priority and mouse clicks
!──────────────────────────────────────────────────────────────────────────
IF INRANGE(isKeystroke, MouseLeft, MouseLeft2) !If mouse click
bbExit = 1 ! Set exit flag
ELSIF MEU:bbAlrtBfrCmd AND bbAlerted ! Elsif ALERTs have priority
bbExit = 1 ! Set exit flag
. ! Endif
!──────────────────────────────────────────────────────────────────────────
EditAction ROUTINE ! Perform an editing function
!──────────────────────────────────────────────────────────────────────────
bbCommand = 1 ! Set command flag
CASE isKeystroke ! Process keystroke:
OF F1Key; HELP(,MEU:sHelpID); HELP ! Help key
OF LeftKey; DO MoveLeft ! Horizontal movement
OF RightKey; DO MoveRight !
OF HomeKey; DO MoveBOL !
OF EndKey; DO MoveEOL !
OF CtrlLeft; DO MovePrevWord !
OF CtrlRight; DO MoveNextWord !
OF UpKey; DO MoveUp ! Vertical movement
OF DownKey; DO MoveDown !
OF PgUpKey; DO PageUp ! Page movement
OF PgDnKey; DO PageDown !
OF CtrlPgUp; DO FirstPage !
OF CtrlPgDn; DO LastPage !
OF InsKey; DO ToggleIns ! Insertion
OF EnterKey; DO InsHRt !
OF CtrlO; DO ToggleCodes ! Text attributes
OF DelKey; DO DelChar ! Deletion
OF BSKey; DO Backspace !
OF CtrlHome; DO DelLine !
OF CtrlEnd; DO DelEOL !
OF CtrlC; DO CopyBlock ! Copy block
OF CtrlM; DO MoveBlock ! Move block
OF CtrlD; DO DelBlock ! Cut block to clipboard
OF CtrlP; DO FileBlock ! Save block to ASCII file
OF CtrlG; ME_PasteFile() ! Paste a file
ELSE ! Else
bbCommand = 0 ! Clear command flag
. ! Endif
!──────────────────────────────────────────────────────────────────────────
OtherKeys ROUTINE ! Handle other keys
!──────────────────────────────────────────────────────────────────────────
IF bbAlerted ! If key is ALERTed
bbExit = 1 ! Set flag
ELSE ! Else
BEEP ! Beep
. ! End if
!──────────────────────────────────────────────────────────────────────────
FileBlock ROUTINE ! Save text block to ASCII file
!──────────────────────────────────────────────────────────────────────────
MES:ssStatus = CENTER(eFileMsg, 76) ! Display source prompt
ME_MarkOn() ! Turn on block marking
DO MoveMode ! Enter restricted move mode
ME_MarkOff() ! Exit marking mode
IF isKeystroke = EnterKey ! If Enter pressed
ME_Copy2File() ! Copy block to file
. ! Endif
MED:bbBlockShow = 0 ! Hide block
ME_SetPage() ! Redisplay page
ME_ShowPage() !
!──────────────────────────────────────────────────────────────────────────
CopyBlock ROUTINE ! Copy text block
!──────────────────────────────────────────────────────────────────────────
MES:ssStatus = CENTER(eCopy1Msg, 76) ! Display source prompt
ME_MarkOn() ! Turn on block marking
DO MoveMode ! Enter restricted move mode
ME_MarkOff() ! Exit marking mode
IF isKeystroke = EnterKey ! If Enter pressed
MES:ssStatus = CENTER(eCopy2Msg, 76) ! Display dest. prompt
DO MoveMode ! Enter restricted move mode
IF isKeystroke = EnterKey ! If Enter pressed
ME_Copy2Clip() ! Copy block to clipboard
ME_PasteClip() ! Paste block
bbNewCol = 1 !
. . ! Endif
MED:bbBlockShow = 0 ! Hide block
ME_SetPage() ! Redisplay page
ME_ShowPage() !
!──────────────────────────────────────────────────────────────────────────
MoveBlock ROUTINE ! Move text block
!──────────────────────────────────────────────────────────────────────────
MES:ssStatus = CENTER(eMove1Msg, 76) ! Display source prompt
ME_MarkOn() ! Turn on block marking
DO MoveMode ! Enter restricted move mode
ME_MarkOff() ! Exit marking mode
IF isKeystroke = EnterKey ! If Enter pressed
MES:ssStatus = CENTER(eMove2Msg, 76) ! Display dest. prompt
DO MoveMode ! Enter restricted move mode
IF isKeystroke = EnterKey ! If Enter pressed
SavPos# = MED:usPosition ! Save current position
ME_Copy2Clip() ! Copy new block
ME_PasteClip() ! Paste new block
MED:bbBlockShow = 1 ! Reshow block
ME_Cut2Clip() ! Cut old block
bbNewCol = 1 !
MED:usPosition = SavPos# ! Restore position
. . ! Endif
MED:bbBlockShow = 0 ! Hide block
ME_SetPage() ! Redisplay page
ME_ShowPage() !
!──────────────────────────────────────────────────────────────────────────
DelBlock ROUTINE ! Delete text block
!──────────────────────────────────────────────────────────────────────────
MES:ssStatus = CENTER(eDeleteMsg, 76) ! Display prompt
ME_MarkOn() ! Turn on block marking
ME_SetPage() ! Redisplay page
ME_ShowPage() !
DO MoveMode ! Enter restricted move mode
IF isKeystroke = EnterKey ! If Enter pressed
ME_Cut2Clip() ! Cut block to clipboard
bbNewCol = 1 !
. ! Endif
ME_MarkOff() ! Turn off block marking
MED:bbBlockShow = 0 !
ME_SetPage() !
ME_ShowPage() !
!──────────────────────────────────────────────────────────────────────────
MoveMode ROUTINE ! Enter restricted move mode
!──────────────────────────────────────────────────────────────────────────
ME_SetPage() ! Redisplay page
ME_ShowPage() !
LOOP ! Loop
ME_CurPos() ! Display cursor
ASK ! Get keystroke
isKeystroke = KEYCODE() ! Get keystroke
DO SaveCol ! Save current column
CASE KEYCODE() ! Process keycode
OF LeftKey; DO MoveLeft ! Horizontal movement
OF RightKey; DO MoveRight !
OF HomeKey; DO MoveBOL !
OF EndKey; DO MoveEOL !
OF CtrlLeft; DO MovePrevWord !
OF CtrlRight; DO MoveNextWord !
OF UpKey; DO MoveUp ! Vertical movement
OF DownKey; DO MoveDown !
OF PgUpKey; DO PageUp ! Page movement
OF PgDnKey; DO PageDown !
OF CtrlPgUp; DO FirstPage !
OF CtrlPgDn; DO LastPage !
OF EnterKey; BREAK !
OF EscKey; BREAK !
. !
DO UpdatePos ! Update position variables
IF MED:bbBlockMark ! If marking a block
MED:isBlockEnd = MED:usPosition ! Update block end
ME_SetPage() ! Invalidate page
. ! Endif
ME_ShowPage() ! Refresh page
. ! End loop
!──────────────────────────────────────────────────────────────────────────
MoveLeft ROUTINE ! Move left one character
!──────────────────────────────────────────────────────────────────────────
IF MED:usPosition > 0 !
MED:usPosition -= 1 !
. !
bbNewCol = 1 !
!──────────────────────────────────────────────────────────────────────────
MoveRight ROUTINE ! Move right one character
!──────────────────────────────────────────────────────────────────────────
IF MED:usPosition < MED:usCharacters - 1 !
MED:usPosition += 1 !
. !
bbNewCol = 1 !
!──────────────────────────────────────────────────────────────────────────
MoveBOL ROUTINE ! Move to beginning of line
!──────────────────────────────────────────────────────────────────────────
MED:usPosition = MED:usLineStart !
bbNewCol = 1 !
!──────────────────────────────────────────────────────────────────────────
MoveEOL ROUTINE ! Move to end of line
!──────────────────────────────────────────────────────────────────────────
MED:usPosition = MED:usLineEnd !
bbNewCol = 1 !
!──────────────────────────────────────────────────────────────────────────
MovePrevWord ROUTINE ! Move to previous word
!──────────────────────────────────────────────────────────────────────────
Position# = ME_WordLeft(MED:usPosition) ! Search for previous word
IF Position# >= 0 ! If one was found
MED:usPosition = Position# ! Set to new position
bbNewCol = 1 !
. ! Endif
!──────────────────────────────────────────────────────────────────────────
MoveNextWord ROUTINE ! Move to next word
!──────────────────────────────────────────────────────────────────────────
Position# = ME_WordRight(MED:usPosition) ! Search for next word
IF Position# >= 0 ! If one was found
MED:usPosition = Position# ! Set to new position
bbNewCol = 1 !
. ! Endif
!──────────────────────────────────────────────────────────────────────────
MoveUp ROUTINE ! Move up one line
!──────────────────────────────────────────────────────────────────────────
IF MED:usLineNdx > 1 ! If not on first line
MED:usLineNdx -= 1 ! Move up
MED:usPosition = ME_LineStart(MED:usLineNdx) !
DO RestoreCol ! Adjust column
. ! Endif
!──────────────────────────────────────────────────────────────────────────
MoveDown ROUTINE ! Move down one line
!──────────────────────────────────────────────────────────────────────────
IF MED:usLineNdx < RECORDS(qLine) ! If not on last line
MED:usLineNdx += 1 ! Move down
MED:usPosition = ME_LineStart(MED:usLineNdx) !
DO RestoreCol ! Adjust column
. ! Endif
!──────────────────────────────────────────────────────────────────────────
PageUp ROUTINE ! Scroll one page up
!──────────────────────────────────────────────────────────────────────────
IF MED:usLineNdx > MED:usPageTop + 1 !
MED:usLineNdx = MED:usPageTop + 1 !
ELSIF MED:usLineNdx > MED:ubWndRows !
MED:usLineNdx -= MED:ubWndRows !
ELSE !
MED:usLineNdx = 1 !
. !
MED:usPosition = ME_LineStart(MED:usLineNdx) !
DO RestoreCol !
!──────────────────────────────────────────────────────────────────────────
PageDown ROUTINE ! Scroll one page down
!──────────────────────────────────────────────────────────────────────────
IF MED:usLineNdx < MED:usPageTop + MED:ubWndRows
MED:usLineNdx = MED:usPageTop + MED:ubWndRows!
ELSE !
MED:usLineNdx += MED:ubWndRows !
. !
IF MED:usLineNdx > RECORDS(qLine) THEN MED:usLineNdx = RECORDS(qLine).
MED:usPosition = ME_LineStart(MED:usLineNdx) !
DO RestoreCol !
!──────────────────────────────────────────────────────────────────────────
FirstPage ROUTINE ! Display first page
!──────────────────────────────────────────────────────────────────────────
MED:usLineNdx = 1 ! Position to first page
MED:usPosition = ME_LineStart(MED:usLineNdx) !
DO RestoreCol ! Adjust column
!──────────────────────────────────────────────────────────────────────────
LastPage ROUTINE ! Display last page
!──────────────────────────────────────────────────────────────────────────
MED:usLineNdx = RECORDS(qLine) ! Position to last page
MED:usPosition = ME_LineStart(MED:usLineNdx) !
DO RestoreCol ! Adjust column
!──────────────────────────────────────────────────────────────────────────
ToggleIns ROUTINE ! Toggle insert/overwrite mode
!──────────────────────────────────────────────────────────────────────────
MED:bbInsertMode = BXOR(MED:bbInsertMode, 1) ! Toggle insert flag
!──────────────────────────────────────────────────────────────────────────
ToggleCodes ROUTINE ! Toggle display of formatting codes
!──────────────────────────────────────────────────────────────────────────
MED:bbShowCodes = BXOR(MED:bbShowCodes, 1) ! Toggle flag
ME_SetPage() ! Set page redisplay
!──────────────────────────────────────────────────────────────────────────
InsChar ROUTINE ! Insert an ordinary character
!──────────────────────────────────────────────────────────────────────────
IF ME_BufrFull() THEN EXIT. ! Exit if buffer is full
MED:bbHasChanged = 1 ! Set flag and insert char
IF MED:bbInsertMode ! Insert character
ME_InsTxt(MED:usPosition, 1, CHR(isKeystroke))
ELSE !
ubChar = ME_GetChar(MED:usPosition) !
IF ubChar = eHRt !
ME_InsTxt(MED:usPosition, 1, CHR(isKeystroke))
ELSE !
ME_PutChar(MED:usPosition, isKeystroke) !
. . !
ME_ReformPar(MED:usPosition) ! Reformat paragraph
DO MoveRight ! Move point position
!──────────────────────────────────────────────────────────────────────────
InsHRt ROUTINE ! Insert a Hard Return code
!──────────────────────────────────────────────────────────────────────────
IF ME_BufrFull() THEN EXIT. ! Exit if buffer is full
MED:bbHasChanged = 1 ! Set flag and insert hard CR
ME_InsTxt(MED:usPosition, 1, CHR(eHRt)) !
ME_ReformDoc() ! Reformat document
DO MoveRight ! Move point position
!──────────────────────────────────────────────────────────────────────────
Backspace ROUTINE ! Delete character before cursor
!──────────────────────────────────────────────────────────────────────────
IF MED:usPosition ! If not at first character
MED:usPosition -= 1 ! Move back one
DO DelChar ! Delete character
. ! Endif
!──────────────────────────────────────────────────────────────────────────
DelChar ROUTINE ! Delete character under cursor
!──────────────────────────────────────────────────────────────────────────
MED:bbHasChanged = 1 ! Set modified flag
IF MED:bbBlockMark ! If block is marked
ME_Cut2Clip() ! Cut to clipboard
bbNewCol = 1 !
ELSE ! Else
ME_DelChar() ! Delete character
. ! Endif
!──────────────────────────────────────────────────────────────────────────
DelLine ROUTINE ! Delete current line
!──────────────────────────────────────────────────────────────────────────
MED:bbHasChanged = 1 ! Set modified flag
ME_DelLine() ! Delete line
bbNewCol = 1 !
!──────────────────────────────────────────────────────────────────────────
DelEOL ROUTINE ! Delete to end-of-line
!──────────────────────────────────────────────────────────────────────────
MED:bbHasChanged = 1 ! Set modified flag
ME_DelEOL() ! Delete to EOL
!──────────────────────────────────────────────────────────────────────────
UpdatePos ROUTINE ! Update position variables
!──────────────────────────────────────────────────────────────────────────
MED:usLineNdx = ME_LineIndex(MED:usPosition)
MED:usLineStart = ME_LineStart(MED:usLineNdx)
MED:usLineEnd = ME_LineEnd(MED:usLineNdx)
!──────────────────────────────────────────────────────────────────────────
SaveCol ROUTINE ! Save current column index
!──────────────────────────────────────────────────────────────────────────
IF bbNewCol ! If column change
isSavCol = MED:usPosition - MED:usLineStart ! Save new column
bbNewCol = 0 ! Clear new column flag
. ! Endif
!──────────────────────────────────────────────────────────────────────────
RestoreCol ROUTINE ! Restore column after vertical motion
!──────────────────────────────────────────────────────────────────────────
DO UpdatePos !
MED:usPosition += isSavCol !
IF MED:usPosition >= MED:usLineEnd !
MED:usPosition = MED:usLineEnd !
. !
!──────────────────────────────────────────────────────────────────────────
StatusLine ROUTINE ! Display status line
!──────────────────────────────────────────────────────────────────────────
IF NOT MEU:bbShowStatus THEN EXIT.
sStatus = 'F1 Help Line: ' & MED:usLineNdx & ' Col: ' & |
1+ (MED:usPosition - MED:usLineStart)
MES:ssStatus = sStatus
!═════════════════════════════════════════════════════════════════════════
! Check for edit buffer overflow
!═════════════════════════════════════════════════════════════════════════
ME_BufrFull FUNCTION
! Return:
bbRetVal BYTE ! Return flag
! Screen:
wBufferFull SCREEN(6,38),COLOR(244)
ROW(1,37) PAINT(1,2),TRN
ROW(2,37) PAINT(4,2),COLOR(128),TRN
ROW(6,3) PAINT(1,36),COLOR(128),TRN
ROW(6,1) PAINT(1,2),TRN
ROW(1,1) STRING('╔═{34}╗')
ROW(2,1) REPEAT(3);STRING('║<0{34}>║') .
ROW(5,1) STRING('╚═{34}╝')
ROW(3,4) STRING('There is no more room for text')
.
CODE
bbRetVal = 0 ! Assume enough room
IF MED:usCharacters >= MED:usMaxChars ! If max lines exceeded
OPEN(wBufferFull) ! Notify user
SETCURSOR !
BEEP; ASK !
CLOSE(wBufferFull) !
bbRetVal = 1 ! Set return flag
. ! Endif
RETURN( bbRetVal ) !